<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/4
 * Time: 8:52
 */

namespace common\helpers;
use Yii;
use yii\db\Connection;

class DbHelper
{
    const NLS_TS_FORMAT_DAY = 'yyyy-mm-dd';
    const NLS_TS_FORMAT_SECONDS = 'yyyy-mm-dd hh24:mi:ssxff';


    /**
     * @param Connection $db
     */
    public static function set_oracle_nls_timestamp_format($db = null){
        if (!$db){
            $db = Yii::$app->db_hr;
        }
        $command = $db->createCommand('alter session set NLS_LANGUAGE=\'AMERICAN\'');
        $command->execute();
        $command = $db->createCommand(sprintf('alter session set NLS_TIMESTAMP_FORMAT=\'%s\'', self::NLS_TS_FORMAT_DAY));
        $command->execute();
    }
}